unit Unit6;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm6 = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    SaveDialog1: TSaveDialog;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form6: TForm6;

implementation

{$R *.dfm}

procedure TForm6.Button2Click(Sender: TObject);
var
  a:array [0..255] of char;
  s:AnsiString;
  f1,f2:file;
  Stream:TMemoryStream;
begin
  if StrToInt(Edit1.Text)=0 then
  begin
    beep();
    ShowMessage('You must enter a correct destination port.');
    exit;
  end;

  SaveDialog1.FileName:=Label4.Caption+'.'+Edit1.Text;
  if not Form6.SaveDialog1.Execute then exit;
  if ExtractFileName(SaveDialog1.FileName)<>Label4.Caption+'.'+Edit1.Text then
  begin
    beep();
    ShowMessage('Please do not change the filename. Try to use a different directory');
    exit;
  end;

  Stream:=TMemoryStream.Create;
  {
  I have wondered by this new Delphi'10 typecasts...
  }
  FillChar(a,256,0);
  s:=AnsiString(Form6.Label5.Caption);
  lstrcpyA(@a,PAnsiChar(s));

  AssignFile(f2,ExtractFilePath(paramstr(0))+'Keyset\public.rsa');
  Reset(f2,1);
  Stream.SetSize(FileSize(f2));
  BlockRead(f2,Stream.Memory^,Stream.Size);
  CloseFile(f2);

  AssignFile(f1,SaveDialog1.FileName);
  Rewrite(f1,1);
  BlockWrite(f1,a,256);
  BlockWrite(f1,Stream.Memory^,Stream.Size);
  CloseFile(f1);
  Exit;

  Stream.Free;
  //Get cUID
  //Write to filename 255 of buf
  //Write there public key    *)
end;

procedure TForm6.Button1Click(Sender: TObject);
begin
  close;
end;

end.
